package cn.itcast.bos.web.action.take_delivery;

import cn.itcast.bos.domain.take_delivery.Order;
import cn.itcast.bos.service.take_delivery.OrderService;
import cn.itcast.bos.utils.BaseAction;
import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.Map;

import static com.opensymphony.xwork2.Action.SUCCESS;

@Namespace("/")
@ParentPackage("json-default")
@Scope("protoType")
@Controller
public class OrderAction extends BaseAction<Order> {
    @Autowired
    private OrderService orderService;
    //根据订单号查询订单的方法
    @Action(value = "order_findOrderByNum",results = {@Result(name="success",type="json")})
    public String findOrderBYNum(){
        Order order = orderService.findbyNum(model.getOrderNum());
        Map<String,Object> result = new HashMap<>();
        if(order==null){
            result.put("success",false);
        }else{
            result.put("success",true);
            result.put("orderData",order);
        }
        ActionContext.getContext().getValueStack().push(result);
        return SUCCESS;
    }
}
